package com.zscat.mallplus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.annotation.IgnoreAuth;
import com.zscat.mallplus.dms.entity.DmsOrder;
import com.zscat.mallplus.dms.service.*;
import com.zscat.mallplus.qsg.*;
import com.zscat.mallplus.ums.entity.UmsMember;
import com.zscat.mallplus.utils.CommonResult;
import com.zscat.mallplus.utils.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 充值套餐管理Controller
 */
@RestController
@Api(tags = "RechargeController", description = "充值套餐相关管理")
@RequestMapping("/api/dms/hexiao")
public class HexiaoController {

    @Autowired
    private IQsgHexiaoService hexiaoService;
    @Autowired
    private IQsgStoreService storeService;

    private static final int DOUYIN = 0;
    private static final int MEITUAN = 1;

    @IgnoreAuth
    @ApiOperation("根据条件查询所有充值套餐套餐管理列表")
    @GetMapping(value = "/list")
    public Object getHeixiaoByPage(int type) {
        try {
            UmsMember member = UserUtils.getCurrentMember();
            QueryWrapper qw = new QueryWrapper();
            qw.eq("member_id", member.getId());
            qw.eq("hexiao_type", type);
            qw.orderByDesc("create_datetime");
            List<QsgHexiao> hexiaos = hexiaoService.list(qw);
            if (hexiaos.size() > 0) {
                for (QsgHexiao hexiao : hexiaos) {
                    QsgStore store = storeService.getById(hexiao.getStoreId());
                    if (null != store) {
                        hexiao.setStoreName(store.getName());
                    }
                }
            }
            return new CommonResult().success(hexiaos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new CommonResult().failed();
    }
}
